﻿using Corina.DataContext.Master;
using Corina.Datamodel.DataObject;
using Corina.Datamodel.Entities;
using Corina.Enumerations;
using Corina.Utilities;
using FineUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Corina.Web.IMS
{
    public partial class Register : PageviewBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoadRelatedData();
            }
        }

        protected void LoadRelatedData()
        {
            ResultInfo userkind = GetInstance<UserKindMaster>().GetAvailableItems();
            _userKinds.DataSource = userkind.Entities.OfType<UserKindInfo>();
            _userKinds.DataBind();

            ResultInfo userindustry = GetInstance<IndustryMaster>().GetAvailableItems();
            _userIndustry.DataSource = userindustry.Entities.OfType<IndustryInfo>();
            _userIndustry.DataBind();
        }

        protected void button_reg_Click(object sender, EventArgs e)
        {
            //UserInfo user = new UserInfo()
            //{
            //    Account = _userAccount.Text,
            //    Name = _userName.Text,
            //    Email = _userEmail.Text,
            //    IndustryId = Convert.ToInt32(_userIndustry.SelectedValue),
            //    UserKindId = Convert.ToInt32(_userKinds.SelectedValue),
            //    Mobile = _userMobile.Text,
            //    Password = SecurityHelper.GetMd5(_userPassword.Text),
            //    Linkman = _userLinkman.Text
            //};

            ResultInfo result = GetInstance<UserMaster>().Register(
                    _userAccount.Text,
                    SecurityHelper.GetMd5(_userPassword.Text),
                    _userName.Text,
                    _userMobile.Text,
                    _userEmail.Text,
                    _userLinkman.Text,
                    Convert.ToInt32(_userIndustry.SelectedValue),
                    Convert.ToInt32(_userKinds.SelectedValue));
            if(result.Result == ResultValue.Succeed)
            {
                Alert.Show("注册成功！", "提示");
            }

        }

        protected void _agreePolicy_CheckedChanged(object sender, CheckedEventArgs e)
        {
            button_reg.Enabled = _agreePolicy.Checked == true;
        }
    }
}